package com.example.yiwei.crm.json;


import com.example.yiwei.crm.entity.UseCareEntity;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2018/1/9.
 */

public class UseCarMessageJson {
    public static List<UseCareEntity> get(String result){
       List<UseCareEntity> list;
        try {
            JSONObject object = new JSONObject(result);
            JSONArray array=object.getJSONArray("list");
            list = new ArrayList<>();
            for (int i=0;i<array.length();i++){
                UseCareEntity entity = new UseCareEntity();
                JSONObject json=array.getJSONObject(i);
                if (json.has("CSC09")){
                    entity.setAddress(json.getString("CSC09"));
                }
                if (json.has("CSC07")){
                    entity.setReason(json.getString("CSC07"));
                }
                if (json.has("CSC10")){
                    entity.setState(json.getString("CSC10"));
                }else {
                    entity.setState("0");
                }
                if (json.has("CSC05L")){
                    entity.setTime(json.getString("CSC05L"));
                }
                list.add(entity);
            }
            return list;
        } catch (JSONException e) {
            e.printStackTrace();
        }

        return null;

    }
}
